package com.ubing.boot.notesforjava.test;

import com.alibaba.excel.annotation.ExcelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Stream;

/**
 * @ClassName : excel
 * @Description : excel
 * @Author : Xxxxx
 * @Date: 2023-03-06 09:56
 */
@Data
@AllArgsConstructor
public class excel {
    @ExcelProperty("字段编码")
    private String fieldname;
    @ExcelProperty("字段名")
    private String labelname;


    public static void main(String[] args) throws IOException {
        String regex = "F\\\".\\\"\\S*";
//        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
        Path path = Paths.get("E:\\GitHub\\notesforjava\\src\\main\\java\\com\\ubing\\boot\\notesforjava\\test\\excel.txt");
//        Stream<String> lines = Files.lines(path);
//        String string = lines.reduce("",(a,b)->a+b);
//        Matcher matcher = pattern.matcher(string);
//        List<excel> list= new ArrayList<>();
//        while (matcher.find()) {
//            String group = matcher.group(0);
//            String substring = group.substring(4, group.length() - 1);
//            list.add(new excel(substring,""));
//            System.out.println(substring);
//            for (int i = 1; i <= matcher.groupCount(); i++) {
//                System.out.println(matcher.group(i));
//            }
//        }

        regex = "IS '\\S*";
        Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
        Stream<String> lines = Files.lines(path);
        String string = lines.reduce("",(a,b)->a+b);
        Matcher matcher = pattern.matcher(string);
        List<excel> list= new ArrayList<>();
        while (matcher.find()) {
            String group = matcher.group(0);
            String substring = null;
            if(group.length() - 9>4){
                substring = group.substring(4, group.length() - 9);
            }
            System.out.println(substring);
            list.add(new excel(substring,""));
            for (int i = 1; i <= matcher.groupCount(); i++) {
                System.out.println(matcher.group(i));
            }
        }
    }
}
